<template>
	<div>
		<!-- :visible.sync="$store.state.mealflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="订单信息" :visible.sync="$store.state.orderInfoflag"
		 width="30%" center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="订单id">
						<el-input v-model="shortOrder.shortid" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="套餐名称">
						<el-input v-model="shortOrder.mealid.mealname" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="基本地址">
						<el-input v-model="shortOrder.u2id.u2baseaddress" style="width:40%" disabled></el-input>
					</el-form-item>
					<el-form-item label="详细地址">
						<el-input v-model="shortOrder.u2id.u2addressinfo" type="textarea" style="width:40%" disabled></el-input>
					</el-form-item>
					<el-form-item label="联系方式">
						<el-input v-model="shortOrder.u2id.u2phone" maxlength=15 disabled></el-input>
					</el-form-item>
					<el-form-item label="目标姓名">
						<el-input v-model="shortOrder.u2id.u2name" maxlength=15 disabled></el-input>
					</el-form-item>
					<!-- 	<el-form-item label="员工姓名">
						<el-input maxlength=15></el-input>
					</el-form-item> -->
					<el-form-item label="员工姓名">
						<el-select v-model="empval" placeholder="请选择">
							<el-option v-for="item in staffList" :key="item.empid" :label="item.empname" :value="item.empid">
							</el-option>
						</el-select>
					</el-form-item>
					<!-- 		  <el-form-item label="活动性质">
		    <el-checkbox-group v-model="mealInfo.mealtype">
		      <el-checkbox label="长期套餐" name=1></el-checkbox>
		      <el-checkbox label="短期套餐" name=2></el-checkbox>
		    </el-checkbox-group>
		  </el-form-item> -->
					<!-- 					<el-form-item label="活动性质">
						<el-radio v-model="mealInfo.mealtype" :label="lab1">长期套餐</el-radio>
						<el-radio v-model="mealInfo.mealtype" :label="lab2">短期套餐</el-radio>
					</el-form-item> -->
					<el-form-item label="订单描述">
						<el-input type="textarea" v-model="shortOrder.shortdetail" maxlength=55 disabled></el-input>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
		 		<el-button type="danger" @click="orderflag1(false)" :disabled="shortOrder.longstate=='3'">结束服务</el-button>
				<el-button @click="mealflagcancel()" >取 消</el-button>
				<el-button type="primary" @click="orderflag(false)" :disabled="shortOrder.longstate!='1'">{{save}}</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		props: {
			staffList: {},
			shortOrder: {
				"longremark": "string",
				"longremark2": "string",
				"longstate": "string",
				"mealid": 0,
				"shortcreatetime": "2019-10-13T10:38:29.844Z",
				"shortdetail": "string",
				"shortid": 0,
				"shortprice": 0,
				"u2id": 0,
				"uid": 0
			}
		},
		data() {
			return {
				lab1: 1,
				lab2: 2,
				flag3: false,
				flag: false,
				flag2: true,
				mealstate2: "1",
				empval: "",
				save: "保存",
				emp: {}
			};
		},
		methods: {
			orderflag(flag) {
				if (this.empval == "") {
					this.save = "请选择员工"
				} else {
					request({
						url: '/Order/shortOrder',
						method: 'patch',
						data: {
							"longremark": this.shortOrder.longremark,
							"longremark2": this.shortOrder.longremark2,
							"longstate": "2",
							"mealid": this.shortOrder.mealid.mealid,
							"shortcreatetime": this.shortOrder.shortcreatetime,
							"shortdetail": this.shortOrder.shortdetail,
							"shortid": this.shortOrder.shortid,
							"shortprice": this.shortOrder.shortprice,
							"u2id": this.shortOrder.u2id.u2id,
							"uid": this.shortOrder.uid.uid
						}
					}).then(res => {

					})
					request({
						url: '/OrderEmp/ShortInfo',
						method: 'post',
						data: {
							"empid": this.empval,
							"shortid": this.shortOrder.shortid,
							"shortinfoidid": 0,
							"shortremark": "string"
						}
					}).then(res => {
						console.log(this.mealstate2)
						return request({
							url: '/Emp/empInfo',
							method: 'get',
							params: {
								// id:this.$store.state.mealid
								"empid": this.empval,
							}
						})
					}).then(res => {
						this.emp = res.data
						return request({
							url: '/Emp/empInfo',
							method: 'patch',
							params: {
								// id:this.$store.state.mealid
								"empid": this.emp.empid,
								"empname": this.emp.empname,
								"empremark": this.emp.empremark,
								"empstate": "1",
								"emptype": this.emp.emptype
							}
						})
					}).then(res => {
						this.$store.commit("updateOrderInfoflag", false)
						this.$router.push("blank_emt")
					})
				}
			},
			orderflag1(flag) {
				/*提醒用户是否删除*/
				     this.$confirm('此操作将永久结束该订单服务, 是否继续?', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
									/*****************/
									if(this.shortOrder.longstate=="1"){
										request({
											url: '/Order/shortOrder',
											method: 'patch',
											data: {
												"longremark": this.shortOrder.longremark,
												"longremark2": this.shortOrder.longremark2,
												"longstate": "3",
												"mealid": this.shortOrder.mealid.mealid,
												"shortcreatetime": this.shortOrder.shortcreatetime,
												"shortdetail": this.shortOrder.shortdetail,
												"shortid": this.shortOrder.shortid,
												"shortprice": this.shortOrder.shortprice,
												"u2id": this.shortOrder.u2id.u2id,
												"uid": this.shortOrder.uid.uid
											}
										}).then(res => {			
											this.$store.commit("updateOrderInfoflag", false)
											this.$router.push("blank_emt")
										})
									}else{
										request({
											url: '/Order/shortOrder',
											method: 'patch',
											data: {
												"longremark": this.shortOrder.longremark,
												"longremark2": this.shortOrder.longremark2,
												"longstate": "3",
												"mealid": this.shortOrder.mealid.mealid,
												"shortcreatetime": this.shortOrder.shortcreatetime,
												"shortdetail": this.shortOrder.shortdetail,
												"shortid": this.shortOrder.shortid,
												"shortprice": this.shortOrder.shortprice,
												"u2id": this.shortOrder.u2id.u2id,
												"uid": this.shortOrder.uid.uid
											}
										}).then(res => {			
											this.$store.commit("updateOrderInfoflag", false)
										})
										
																				
										request({
											url: '/OrderEmp/ShortinfoBYshortId',
											method: 'get',
											params: {
												// id:this.$store.state.mealid
												shortId: this.shortOrder.shortid
											}
										}).then(res => {
											
											return 	request({
											url: '/Emp/empInfo',
											method: 'get',
											params: {
												// id:this.$store.state.mealid
												empid: res.data.empid
											}
										})										
										}).then(res=>{
										return request({
												url: '/Emp/empInfo',
												method: 'patch',
												params: {
													// id:this.$store.state.mealid
													"empid": res.data.empid,
													"empname": res.data.empname,
													"empremark": res.data.empremark,
													"empstate": "2",
													"emptype": res.data.emptype
												}
											})
										}).then(res => {
											this.$store.commit("updateOrderInfoflag", false)
											this.$router.push("blank_emt")
										})
										
										
											
										
										
									}

									/*****************/
				          this.$message({
				            type: 'success',
				            message: '结束成功!'
				          });
				        }).catch(() => {
				          this.$message({
				            type: 'info',
				            message: '已取结束'
				          });          
				        });			
			},
			mealflagcancel() {
				this.$store.commit("updateOrderInfoflag", false)
			},
			onSubmit() {
				console.log('submit!');
			}
		}
	};
</script>

<style>
</style>
